﻿using Microsoft.AspNetCore.Mvc.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Gear.Web.Api.DynamicRouter
{
    /// <summary>
    /// 控制器判断类
    /// </summary>
    public class DynamicWebApiControllerFeatureProvider: ControllerFeatureProvider
    {
        /// <summary>
        /// 判断是否可以成为控制器
        /// </summary>
        /// <param name="typeInfo"></param>
        /// <returns></returns>
        protected override bool IsController(TypeInfo typeInfo)
        {
            if (typeof(IDynamicRoute).IsAssignableFrom(typeInfo))
            {
                if (!typeInfo.IsInterface &&
                    !typeInfo.IsAbstract &&
                    !typeInfo.IsGenericType &&
                    typeInfo.IsPublic)
                {
                    return true;
                }
            }

            return false;
        }
    }
}
